<?php

namespace app\index\controller;

use app\admin\model\Application;
use app\admin\model\Banner;
use app\admin\model\Download;
use app\admin\model\News;
use app\admin\model\Page;
use app\admin\model\Product;
use app\admin\model\Category;

class Index extends Base
{

    public function index()
    {

        $banner = Banner::order('weigh desc')->select()->toArray();
        $ling = Application::order('weigh desc')->select();
        $indexProduct = Product::order('weigh desc')->limit(4)->select();
        $about = Page::order('weigh desc')->where('id', 1)->find();
//        var_dump($banner);
        // 渲染默认模板输出
        require VIEW_PATH . '/index.php';
    }

    public function page()
    {
        parse_str($_SERVER["QUERY_STRING"], $result);

        $array = explode('/',$result['s']);
        $id = (int)end($array);
        $data = Page::where('id', $id)->find();

        // 渲染默认模板输出
        require VIEW_PATH . '/page.php';
    }

    public function product()
    {

        parse_str($_SERVER["QUERY_STRING"], $result);

        $array = explode('/',$result['s']);
        $id = (int)end($array);
        $data = Product::where('category_id', $id)->order('id,weigh desc')->select();
        // 渲染默认模板输出
        require VIEW_PATH . '/product.php';
    }

    public function productDetail()
    {

        parse_str($_SERVER["QUERY_STRING"], $result);

        $array = explode('/',$result['s']);
        $id = (int)end($array);
        $data = Product::where('id', $id)->find();
        $dataCategory = Category::where('id', $data['category_id'])->find();
//        var_dump($banner);
        // 渲染默认模板输出
        require VIEW_PATH . '/productDetail.php';
    }

    public function ling()
    {

        parse_str($_SERVER["QUERY_STRING"], $result);

        $array = explode('/',$result['s']);
        $id = (int)end($array);
        $data = Application::where('category_id', $id)->select();
        // 渲染默认模板输出
        require VIEW_PATH . '/ling.php';
    }

    public function lingDetail()
    {

        parse_str($_SERVER["QUERY_STRING"], $result);

        $array = explode('/',$result['s']);
        $id = (int)end($array);
        $data = Application::where('id', $id)->find();
        $dataCategory = Category::where('id', $data['category_id'])->find();
        require VIEW_PATH . '/lingDetail.php';
    }

    public function news()
    {

        parse_str($_SERVER["QUERY_STRING"], $result);

        $array = explode('/',$result['s']);
        $id = (int)end($array);
        $data = News::where('category_id', $id)->order('id,weigh desc')->select();
        // 渲染默认模板输出
        require VIEW_PATH . '/news.php';
    }


    public function newsDetail()
    {

        parse_str($_SERVER["QUERY_STRING"], $result);

        $array = explode('/',$result['s']);
        $id = (int)end($array);
        $data = News::where('id', $id)->find();
        $dataCategory = Category::where('id', $data['category_id'])->find();
        require VIEW_PATH . '/newsDetail.php';
    }

    public function download()
    {
        $data = Download::select();
        // 渲染默认模板输出
        require VIEW_PATH . '/download.php';
    }
}
